package java_class_work.week07;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author Tiam
 * @Date 2022/10/24 13:53
 * @Description:
 */
public class JDBCUtilsTest {
    public static void main(String[] args) {
        Statement statement = JDBCUtils.getStatement();

        String sql = "select * from user";
        try {
            ResultSet resultSet = statement.executeQuery(sql);
            // 通过游标获取每一行的数据
            while (resultSet.next()) {
                //通过字段名
                String username = resultSet.getString("username");
                String pwd = resultSet.getString("pwd");
                int role = resultSet.getInt("role");
                System.out.println(username+"\t"+pwd+"\t"+role);
            }
            resultSet.close();
            JDBCUtils.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
